package com.ptmall.app.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.bean.FyBean;
import com.ptmall.app.bean.LogBean;
import com.ptmall.app.ui.activity.OrderDetilActivity;
import com.ptmall.app.utils.GlideUtil;
import com.ptmall.app.utils.TimeUtil;
import com.ptmall.app.view.NoScrollListView;

import java.util.List;


/**
 * Created by Administrator on 2018/1/12.
 */

public class FyAdapter extends BaseAdapter {

    private Context mContext;
    private List<FyBean> mDataList;
    private LayoutInflater mLayoutInflater;
    private String type;

    public void setType(String type) {
        this.type = type;
    }

    ClickInterface clickInterface;


    public void setClickInterface(ClickInterface clickInterface) {
        this.clickInterface = clickInterface;
    }


    public FyAdapter(Context context, List<FyBean> list) {
        this.mContext = context;
        this.mDataList = list;
        this.mLayoutInflater = LayoutInflater.from(mContext);
    }

    public void pushData(List<FyBean> list) {
        this.mDataList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (mDataList == null) {
            return 0;
        }
        return mDataList.size();
    }


    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = mLayoutInflater.inflate(R.layout.item_fygl, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        FyBean bean = mDataList.get(position);

        if(type.equals("1")){
            viewHolder.btn.setVisibility(View.VISIBLE);
            viewHolder.time.setVisibility(View.GONE);
            viewHolder.price.setText(bean.commission+"");
        }else {
            viewHolder.btn.setVisibility(View.GONE);
            viewHolder.time.setVisibility(View.VISIBLE);
            viewHolder.price.setText(bean.money+"");
        }

        GlideUtil.showImg(mContext,bean.avatar+"",viewHolder.logo);
        viewHolder.name.setText(bean.name+"");
        viewHolder.time.setText(TimeUtil.getStrTime(bean.create_time)+"");

        viewHolder.btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickInterface.btn1Click(bean);
            }
        });

        return convertView;
    }

    class ViewHolder {
        ImageView logo;
        TextView name, price, btn,time;


        ViewHolder(View view) {
            logo = (ImageView) view.findViewById(R.id.logo);
            name = (TextView) view.findViewById(R.id.name);
            price = (TextView) view.findViewById(R.id.price);
            btn = (TextView) view.findViewById(R.id.btn);
            time = (TextView) view.findViewById(R.id.time);
        }
    }


    public interface ClickInterface {
        void btn1Click(FyBean fyBean);

    }


}
